//
//  ExpressDetailViewController.m
//  ChunLaiZhuangClient
//
//  Created by zouzhisheng on 16/4/28.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "ExpressDetailViewController.h"
#import "ExpressFrameModel.h"
#import "CustomExpressDetailTableViewCell.h"
@interface ExpressDetailViewController ()<UITableViewDataSource,UITableViewDelegate>{
    NSMutableArray *dataArray;
}


@end

@implementation ExpressDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    dataArray=[[NSMutableArray alloc] init];
    [self setNaviTitle:@"物流信息"];
    [self setNaviLeftButton:@""];
    [self loadExpressData];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)loadExpressData{
    __weak typeof (self) weakSelf = self;
    [[LKDHud shareHud] showLoadingView];
    [ApiClient getExpressDetailOrderID:self.orderID didFinishLoaded:^(ExpressInfoModel *model, NSString *path) {
        [[LKDHud shareHud] hideLoadingView];
        for(ExpressDetailModel * detailModel in model.data.traces){
           ExpressFrameModel*frameModel=[[ExpressFrameModel alloc] init];
            frameModel.expressModel=detailModel;
            [dataArray addObject:frameModel];
        }
       
        if (![weakSelf.view.subviews containsObject:weakSelf.displayView]) {
            [weakSelf.view addSubview:weakSelf.displayView];
        }else{
            [weakSelf.displayView reloadData];
        }

    } didFailLoaded:^(NSError *error, NSString *path) {
        [[LKDHud shareHud] hideLoadingView];

    }];
    
}
-(UITableView*)displayView{
    if (!_displayView) {
        _displayView=[[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
        _displayView.delegate=self;
        _displayView.dataSource=self;
        _displayView.backgroundColor=[UIColor clearColor];
        _displayView.tableFooterView=[[UIView alloc] initWithFrame:CGRectZero];
        // [_displayView setSeparatorColor:[UIColor redColor]];
    }
    return _displayView;
}
#pragma mark-UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomExpressDetailTableViewCell *cell=[CustomExpressDetailTableViewCell cellWithTableView:tableView];
    cell.frameModel=dataArray[indexPath.row];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ExpressFrameModel *frameModel=dataArray[indexPath.row];
    return frameModel.cellHeigh;
}
-(void)viewDidLayoutSubviews
{
    if ([self.displayView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.displayView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.displayView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.displayView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
